//
//  HomeVC.swift
//  Xiaozihui
//
//  Created by 校企荟 on 2017/8/21.
//  Copyright © 2017年 校企荟. All rights reserved.
//

import UIKit

let xunjianCellID = "xunjianCell"
let baoxiuCellID = "baoxiuCell"
let servicemanCellID = "servicemanCell"
let histogramCellID = "histogramCell"
//let propertyCellID = "propertyCell"


class HomeVC: BaseVC {
    
    lazy var viewModel: HomeVM = {
        return HomeVM()
    }()
    
    lazy var tableView:BaseTableView = {
        let tv = BaseTableView(frame: CGRect.zero, style: .grouped)
        tv.delegate = self
        tv.dataSource = self
        tv.register(XunjianCell.self, forCellReuseIdentifier: xunjianCellID)
        tv.register(BaoxiuCell.self, forCellReuseIdentifier: baoxiuCellID)
        tv.register(HistogramCell.self, forCellReuseIdentifier: histogramCellID)
        tv.register(ServicemanCell.self, forCellReuseIdentifier: servicemanCellID)
//        tv.register(PropertyPieCell.self, forCellReuseIdentifier: propertyCellID)
        tv.rowHeight = UITableViewAutomaticDimension
        tv.estimatedRowHeight = 200
        return tv
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.titleView = UILabel(content: "可视化报修平台", textFont: UIFont.boldSystemFont(ofSize: 17), color: mainColor, alignment: .center, numberOfLine: 1)
        
//        loadData()
    }

    
    func loadData() {
        viewModel.loadData { (isSuccess) in
            
        }
    }
    
    internal override func setupUI() {
        view.addSubview(tableView)
        
        tableView.snp.makeConstraints { (make) in
            make.edges.equalTo(view)
        }

        tableView.tableHeaderView = HomeHeadView(frame: CGRect.zero)
    }

}


// MARK: UItableViewDelegate UITableViewDataSource
extension HomeVC :UITableViewDelegate,UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return UIView()
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return UIView()
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.1
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0.1
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell : UITableViewCell
        
        switch indexPath.row {
        case 0:
            cell = tableView.dequeueReusableCell(withIdentifier: xunjianCellID, for: indexPath)
        case 1:
            cell = tableView.dequeueReusableCell(withIdentifier: servicemanCellID, for: indexPath)
        default:
            cell = tableView.dequeueReusableCell(withIdentifier: histogramCellID, for: indexPath)
            
            //            cell = tableView.dequeueReusableCell(withIdentifier: propertyCellID, for: indexPath)
        }
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row == 0 {
//            navigationController?.pushViewController(OrderListVC(), animated: true)
            
            navigationController?.pushViewController(BaoxiuVC(), animated: true)
        }
        
        if indexPath.row == 1 {
            navigationController?.pushViewController(PropertyDetailVC(), animated: true)
            
        }
    }
}
